import { PagedRequestDto } from "@shared/component-base";

export interface IUserDto {
  code: string;
  name: string;
  mail: string;
  phone: string;
  password:string;
  id: number;
}

export class UserDto implements IUserDto {
  code: string;
  name: string;
  mail: string;
  phone: string;
  password: string;
  id: number;

  constructor(data?: IUserDto) {
    if (data) {
      for (var property in data) {
        if (data.hasOwnProperty(property))
          (<any>this)[property] = (<any>data)[property];
      }
    }
  }

  init(data?: any) {
    if (data) {
      this.code = data["userName"];
      this.name = data["name"];
      this.mail = data["mail"];
      this.phone = data["phone"];
      this.password = data["password"];
      this.id = data["id"];
    }
  }

  static fromJS(data: any): UserDto {
    data = typeof data === 'object' ? data : {};
    let result = new UserDto();
    result.init(data);
    return result;
  }

  toJSON(data?: any) {
    data = typeof data === 'object' ? data : {};
    data["code"] = this.code;
    data["name"] = this.name;
    data["mail"] = this.mail;
    data["phone"] = this.phone;
    data["password"] = this.password;
    data["id"] = this.id;
    return data;
  }

  clone() {
    const json = this.toJSON();
    let result = new UserDto();
    result.init(json);
    return result;
  }
}

export class UserListQueryDto extends PagedRequestDto {
  phone: string;
  keywords: string;
  enabled: boolean;

  init(data?: any) {
    if (data) {
      this.pageIndex = data["pageIndex"];
      this.pageSize = data["pageSize"];
      this.sortField = data["sortField"];
      this.sortOrder = data["sortOrder"];
      this.keywords = data["keywords"];
      this.phone = data["phone"];
      this.enabled = data["enabled"];
    }
  }

  toJSON(data?: any) {
    data = typeof data === 'object' ? data : {};
    data["pageIndex"] = this.pageIndex;
    data["pageSize"] = this.pageSize;
    data["sortField"] = this.sortField;
    data["sortOrder"] = this.sortOrder;
    data["phone"] = this.phone;
    data["keywords"] = this.keywords;
    data["enabled"] = this.enabled;
    return data;
  }
}
